﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HitchHikersGuideToTheGalaxy.Models;
using System.Web.Security;

namespace HitchHikersGuideToTheGalaxy.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        private void Initialize()
        {
            // Setjum gögn inn í ViewData fyrir listann hægramegin með nýjustu ferðum
            TourDestRepository tourDest = new TourDestRepository();
            IEnumerable<TourDest> upCommingTours = tourDest.FindUpcomingTourDests();
            ViewData["UpcomingTours"] = upCommingTours;
        }

        public ActionResult Index()
        {
            Initialize();

            //ViewData["Message"] = "Hér mun koma kort";
            ViewData["UserName"] = HttpContext.User.Identity.Name.ToString();

            TourDestRepository tourDest = new TourDestRepository();
            IEnumerable<TourDest> upCommingTours = tourDest.FindAllTourDests(); //TODO: Skipta út línum eftir test.
            //IEnumerable<TourDest> upCommingTours = tourDest.FindUpcomingTourDests();
            ViewData["UpcomingTours"] = upCommingTours;

            ////TODO: Testing TourRepository querys, henda út þegar við hættum að testa
            //ITourDestRepository t = new TourDestRepository();
            //IQueryable<TourDest> bla = t.FindAllTourDests();

            //List<TourDest> bla2 = new List<TourDest>();

            //foreach (var item in bla)
            //{
            //    bla2.Add(item);
            //}

            //MembershipUser username;
            //username = Membership.GetUser("kgh");
            ////username.
            ////END TEST

            return View();
        }

        public ActionResult About()
        {
            Initialize();

            return View();
        }
    }
}
